<template>
    <div class="information">
        <div class="header"><img class="return_img" src="@/assets/Return.png" style="width:.23rem;height:.4rem;" v-on:click="back">我的信息</div>
        <ul>
            <li><p>头像</p><span><img :src="userInfo.photo" width='25' alt=""></span></li>
            <li><p>账号</p><span>{{userInfo.account }}</span></li>
            <li><p>姓名</p><span>{{userInfo.name  }}</span></li>
            <li><p>电话</p><span>{{userInfo.mobile  }}</span></li>
            <li  v-if="userInfo.sex == 1"><p>性别</p><span>男</span></li>
            <li  v-if="userInfo.sex == 2"><p>性别</p><span>女</span></li>
            <li><p>酒店</p><span>{{userInfo.hotelName  }}</span></li>
            <li><p>部门</p><span>{{userInfo.depName }}</span></li>
            <li><p>职位</p><span>{{userInfo.position  }}</span></li>
            <li @click="request"><p>绑定的微信</p><span>{{ userInfo.nickName  }}</span></li>
            <li @click="mycode"><p>我的二维码</p><span>></span></li>
        </ul>
        <x-button @click.native="_login">退出登录</x-button>
        <div v-transfer-dom>
            <confirm v-model="show"
            title="您要重新绑定微信吗？"
            @on-confirm="onConfirm">                
            </confirm>
        </div>
    </div>
</template>
<script>
import {
  XHeader,
  XButton,
  TransferDomDirective as TransferDom,
  Confirm
} from "vux";
import { getPersonalInfo } from "@/service/home.js";
export default {
  directives: {
    TransferDom
  },
  components: { XHeader, XButton, Confirm },
  data() {
    return {
      userInfo: "",
      show: false
    };
  },
  created() {
    this._getPersonalInfo();
  },
  methods: {
    mycode() {
      this.$router.push("/my/mycode");
    },
    back() {
      this.$router.push("/index");
    },
    request() {
      this.show = true;
      //如果有授权
      return false;
    },
    onConfirm() {
      var url = "http://staff.ihotelvip.com/my/code2";
      var appid = "wx9a16008c72a9cf50";
      url =
        "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" +
        appid +
        "&redirect_uri=" +
        url +
        "&response_type=code&scope=snsapi_userinfo&state=STATE&connect_redirect=1#wechat_redirect";
      window.location.href = url;
    },
    _login() {
      localStorage.setItem("token", null);
      this.$router.push({ path: "/login" });
    },
    _getPersonalInfo() {
      getPersonalInfo().then(res => {
        this.userInfo = res.data.userInfo;
        console.log(this.userInfo);
        sessionStorage.setItem("userInfo", JSON.stringify(this.userInfo));
      });
    }
  }
};
</script>
<style scoped lang="less">
.information {
  ul {
    background: #fff;
    margin-top: 0.5rem;
    li {
      height: 50px;
      line-height: 50px;
      border-bottom: 1px solid #ddd;
      width: 90%;
      margin: 0 auto;
      p {
        float: left;
      }
      span {
        float: right;
        color: #888888;
      }
    }
  }
  .weui-btn {
    width: 90%;
    margin: 0.5rem auto;
  }
}
</style>
